﻿// Bravura : A music composition and audio synthesis framework.
//
// Copyright © 2011 Paul Vanukoff (pvanukoff@gmail.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.

using System.Collections.Generic;
using Bravura.Core.Common;
using System.Reflection;
using System;

namespace Bravura.Core.PluginLib
{
	/// <summary>
	/// A minimal base class for audio plugins.
	/// </summary>
	public abstract class AudioPluginBase
	{
		#region Fields

		protected IAudioPluginHost _host = null;
		protected int _sampleRate = 48000;
		protected double _sampleTime = 1.0 / 48000;

		#endregion

		/// <summary>
		/// Create a new AudioPlugin instance.
		/// </summary>
		protected AudioPluginBase(IAudioPluginHost host, int sampleRate)
		{
			_host = host;
			_sampleRate = sampleRate;
			_sampleTime = 1.0 / sampleRate;
		}

		#region IAudioPlugin Implementation

		/// <summary>
		/// Configures the plugin.
		/// </summary>
		public virtual void Configure(List<IConfigItem> configuration)
		{
			// override to support
		}

		/// <summary>
		/// Sets a value of a plugin (run-time) setting.
		/// </summary>
		public virtual void SetPluginSetting(string key, string value)
		{
			// override to support
		}

		/// <summary>
		/// Sets a value of a plugin (run-time) control.
		/// </summary>
		public virtual void SetPluginControl(string key, double value)
		{
			// override to support
		}

		/// <summary>
		/// Acquire or open plugin resources before use.
		/// </summary>
		public abstract void Open();

		/// <summary>
		/// Process "count" number of samples.
		/// </summary>
		public abstract void Process(int count);

		/// <summary>
		/// Release or close plugin resources.
		/// </summary>
		public abstract void Close();

		#endregion
	}
}
